﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// ShortSerializer handles the conversion between big/little endian
    /// encoding to make sure the data is cross platform safe.
    /// </summary>
    public class ShortSerializer : AbstractSerializer<short>
    {
        public static ShortSerializer Instance = new ShortSerializer();

        public ShortSerializer()
        {
        }
        public override byte[] ToBytes(short obj)
        {
            return ConvertToBigEndianBytes(BitConverter.GetBytes(obj));
        }
        public override ByteBuffer ToByteBuffer(short obj)
        {
            return new ByteBuffer(ToBytes(obj));
        }
        public override short FromBytes(byte[] bytes)
        {
            return BitConverter.ToInt16(ConvertFromBigEndianBytes(bytes),0);
        }
        public override short FromByteBuffer(ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
    }
}
